package com.jule.chat.network.handler;


import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author xujian 这是个测试包 后续会删除
 */
public class ChatWebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
    private final static Logger logger = LoggerFactory.getLogger(ChatWebSocketFrameHandler.class);

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame msg){
        if(msg instanceof TextWebSocketFrame){
            logger.info("收到 TextWebSocketFrame");
            //ctx.fireChannelRead(msg.retain());
            ctx.close();
        }else if(msg instanceof BinaryWebSocketFrame){
            logger.info("收到 BinaryWebSocketFrame");
            ctx.fireChannelRead(msg.retain());
        }else if(msg instanceof PingWebSocketFrame){
            logger.info("收到 PingWebSocketFrame");
            ctx.writeAndFlush(new PongWebSocketFrame());
        }else {
            logger.info("收到未知包");
        }
    }
}
